<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <meta http-equiv="pragma" content="no-cache" />
        <meta http-equiv="cache-control" content="no-cache" />
        <meta http-equiv="expires" content="0" />
        <title></title>
        <link rel="stylesheet" rev="stylesheet" href="{{$http_url}}/css/style.css" type="text/css" media="all" />
    </head>
    <body class="ContentBody">
        <form action="{{$http_url}}/examination/addEditorProcess/" method="post"  name="form" >
            <div class="MainDiv">
                <table width="99%" border="0" cellpadding="0" cellspacing="0" class="CContent">
                    <tr>
                        <th class="tablestyle_title" >{{if $depid}}编辑审批策略{{else}}添加审批策略{{/if}}</th>
                    </tr>
                    <tr>
                        <td class="CPanel">
                            <table border="0" cellpadding="0" cellspacing="0" style="width:100%">
                                <tr>
                                    <td width="100%">
                                           <table border="0" cellpadding="2" cellspacing="1" style="width:100%">
                                                <tr>
                                                    <td nowrap  width="10%" align="right">审批流程名称:</td>
                                                    <td width="35%"><input id="process_name" name='process_name' type="text" class="text" style="width:200px" {{if $details.0.name}} value="{{$details.0.name}}" {{/if}} /></td>
                                                </tr>
                                                <tr>
                                                    <td nowrap align="right" width="10%">审批流程类型:</td>
                                                    <td width="35%">
                                                        <select name="rule_type" id="type">
                                                            <option value="0" {{if $details.0.type==0}} selected="selected" {{/if}}>刻录审批策略</option>
                                                            <option value="1" {{if $details.0.type==1}} selected="selected" {{/if}}>数据交换审批策略</option>
                                                        </select>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td nowrap align="right" width="10%">部门:</td>
                                                    <td width="35%">
                                                        <select name="groud">
                                                            {{foreach from=$groud item=list}}
                                                            <option value="{{$list.id}}" {{if $details.0.group_id == $list.id}} selected="selected" {{/if}}>{{$list.nickname}}</option>
                                                            {{/foreach}}
                                                        </select>
                                                    </td>
                                                </tr>
                                                <tr>
                                                    <td nowrap align="right" width="10%">密级:</td>
                                                    <td width="35%">
                                                        <select name="levelId" id="level_id">
                                                            <option value="5" >----</option>
                                                            <option value="4" {{if $details.0.level_id == 4}} selected="selected" {{/if}}>非密</option>
                                                            <option value="3" {{if $details.0.level_id == 3}} selected="selected" {{/if}}>内部</option>
                                                            <option value="2" {{if $details.0.level_id == 2}} selected="selected" {{/if}}>秘密</option>
                                                            <option value="1" {{if $details.0.level_id == 1}} selected="selected" {{/if}}>机密</option>
                                                            <option value="0" {{if $hid && $details.0.level_id == 0}} selected="selected" {{/if}}>绝密</option>
                                                        </select>
                                                    </td>
                                                </tr>
                                            </table>
                                    </td>
                                </tr>
                                <tr>
                                     <table border="0" cellpadding="2" cellspacing="1" style="width:100%" id="table_div" {{if !$hid && $details.0.check_user_ids}}style="display: none;"{{/if}}>
                                        {{if $hid && $details.0.check_user_ids}}
                                        {{$html}}
                                         {{/if}}
                                     </table>
                                </tr>
                                <tr>
                        <td colspan="2" align="center" height="50px">
                            <input id="submit" type="submit" name="submit" value="保存" class="button" />　
                            <input type="button" name="Submit2" value="返回" class="button" onclick="window.history.go(-1);"/>
                        </td>
                    </tr>
                            </table>
            </div>
             <input type="hidden" name="levelnum" id="levelnum" {{if $hid}} value="{{$count_ids}}"{{/if}}>
             <input type="hidden" name="level_userid" id="level_userid">
             {{if $hid}}
            <input type="hidden" name="job" value="job">
            <input type="hidden" name="id" value="{{$hid}}" id="up_id">
            {{/if}}
        </form>
        <input type="hidden" id="process" name="process" value={{$process}}>
        <script type="text/javascript" src="{{$http_url}}/js/jquery.min.js"></script>
        <script type="text/javascript" src="{{$http_url}}/js/authentication.js"></script>
        <script type="text/javascript">
             $(document).ready(function(){
                function approvalhtml(type,id){
                    $("#table_div").html("");
                   var process=$("#process").val();
                   var json_obj=eval("("+process+")");
                    var html='';
                    $("#levelnum").val(0);
                   for(var key in json_obj){
                     if(json_obj[key]["type"]==type){
                         var arr=json_obj[key]["level"].split(';');
                         for(k in arr){
                             var a=arr[k].split(',');
                             if(a[1]==1){
                                if(a[0]==id){
                                    var i;
                                    $("#levelnum").val(a[2]);
                                    for(i=1;i<=a[2];i++){
                                        html+="<tr><td width='100%'>";
                                        html+="<fieldset style='height:100%;'>";
                                        html+="<legend>"+i+"级审批</legend>";
                                        html+="<table border='0' cellpadding='2' cellspacing='1' style='width:100%'>";
                                        html+="<tr><td nowrap align='right' width='10%'>选择审批人:</td>";
                                        html+="<td width='35%'>";
                                        html+="<table border='1' cellpadding='2' cellspacing='1' style='width:50%'>";
                                        html+="{{foreach from=$userlist item=user_list}}<tr><td>";
                                        html+="<input type='checkbox' name='checkbox_"+i+"' value='{{$user_list.id}}'></td><td>{{$user_list.username}}</td>";
                                        html+="<td>{{$user_list.group_nickname}}</td></tr>{{/foreach}}";
                                        html+="</table>";
                                        html+="</td></tr></table>";
                                        html+="</fieldset></td></tr>";
                                    }
                                }
                             }
                         }
                     }
                   }
                   $("#table_div").html(html);
                   $("#table_div").show();
                }
                $("#level_id").change(function(){
                    if($(this).val()!=''){
                        approvalhtml($("#type").val(),$(this).val());
                    }
                });
                $("#type").change(function(){
                    if($("#level_id").val()!='5'){
                        approvalhtml($(this).val(),$("#level_id").val());
                    }
                });
                $("#submit").click(function(){
                    var num=$('#levelnum').val();
                    var str='';
                    for(i=1;i<=num;i++){
                        var r=document.getElementsByName("checkbox_"+i);
                        var str_bak='';
                            for(var j=0;j<r.length;j++){
                                if(r[j].checked){
                                 str_bak+=r[j].value+'|';
                                }
                             }
                            if(str_bak==''){
                                alert("请选择第"+i+"级审批人");
                                return false;
                            }
                            str+=str_bak.substring(0,str_bak.length-1);
                            str+=">";
                    }
                    str=str.substring(0,str.length-1);
                    $("#level_userid").val(str);
                });
            });
        </script>
    </body>
</html>
